package com.itwill.ecom;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		System.out.println(request.getContextPath());

		HttpSession session = request.getSession();
	  
		if (session == null) {
			response.sendRedirect("/web/");
			return false;
		}
	  
		String user = (String)session.getAttribute("user");
		if (user == null || user.equals("")) { 
			response.sendRedirect("/web/");  
			return false;
		}
		return true;
	 }
}